<?php get_header(); ?>
<?php if ( have_posts() )	the_post(); ?>
		<?php 
				global $post_id;
		        $cs_default_pages = get_option("cs_default_pages");
                if ( $cs_default_pages <> "" ) {
                    $xmlObject = new SimpleXMLElement($cs_default_pages);
						$cs_layout = $xmlObject->cs_layout;
						$cs_sidebar_left = $xmlObject->cs_sidebar_left;
						$cs_sidebar_right = $xmlObject->cs_sidebar_right;
                        $cs_pagination = $xmlObject->cs_pagination;
                        $record_per_page = $xmlObject->record_per_page;
						if($cs_pagination == 'Single Page'){$record_per_page = '-1';}
                }
				if ( $cs_layout == "left" ) {
					$cs_layout = "two-thirds column right";
					$show_sidebar = $cs_sidebar_left;
				}
				else if ( $cs_layout == "right" ) {
					$cs_layout = "two-thirds column left";
					$show_sidebar = $cs_sidebar_right;
				}
				else $cs_layout = "sixteen columns left";				
            ?>
			<div class="container row">
            	 <div class="<?php echo $cs_layout;?>">
                	<h1 class="heading"><?php echo 'Tag :  '.single_tag_title( '', false );?></h1>
					<?php
						if ( empty($_GET['page_id_all']) ) $_GET['page_id_all'] = 1;
							if ( $cs_pagination == "Single Page" ) $cs_pagination = -1;
							$general_category = single_tag_title( '', false );						
							$newterm = get_term_by('slug', $general_category, 'post_tag');
							$newpost = 'posts_per_page=-1&tag='.$newterm->slug.'&post_type=post';
							$newquery_tag = new WP_Query($newpost);
								$count_post = 0;
									while ( $newquery_tag->have_posts() ) : $newquery_tag->the_post(); 
											$count_post++;						
									endwhile;
							$new = 'posts_per_page='.$record_per_page.'&tag='.$newterm->slug.'&paged='.$_GET["page_id_all"].'';
								$newquery = new WP_Query($new);
									while ( $newquery->have_posts() ) : $newquery->the_post(); 
										if ( is_archive() || is_search() ) :
										$image_id = get_post_thumbnail_id();  
										$image_url = wp_get_attachment_image_src($image_id,'');	
										$day = date('l', strtotime(get_the_time('F jS, Y')));
										$day_num = date("d", strtotime(get_the_time('F jS, Y')));
										$day_alpha = date("M", strtotime(get_the_time('F jS, Y')));												
					?>
                    <!-- Blog Post Start -->
                    <div class="in-sec">
                        <div class="blog-detail">
                            <div class="blog-opts">
                                <div class="date">
                                    <h6><?php echo $day;?></h6>
                                    <h1><?php echo $day_num.$day_alpha?></h1>
                                </div>
								<div class="desc">
                                    <h4><a href="<?php echo get_permalink();?>"><?php echo get_the_title();?></a></h4>
                                    <p class="by">Posted by <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) ); ?>"><?php echo get_the_author();?></a></p>
                                    <p class="coments"><a href="<?php echo get_permalink();?>#comments"><?php echo get_comments_number($post_id);?> Comments</a></p>
                                    <?php $tag_post = wp_get_post_tags( $post->ID );?>
                                    <p class="tags">
                                        <?php
										$counterr = 0;
										foreach(get_the_category() as $values){
											if($counterr == 0){ echo 'Category:  ';}
											$counterr++;
											echo '<a href="'.get_category_link($values->term_id).'">'.$values->name.'</a>  ';											

											}										
										?> 
                                    </p>
                                    <div class="clear"></div>
                                </div>
                            </div>
                            <div class="blog-desc">
                            	<p class="txt">
                                	<?php the_excerpt();?>
                                </p>
                            </div>
                            <div class="clear"></div>
                        </div>
                    </div>
					<?php endif; endwhile;	?>
                    <!-- Blog Post End -->
            <?php
			$qrystr = '';
			if(cs_pagination($count_post, $record_per_page,$qrystr) <> ''){
				// pagination start
				if ( $cs_pagination == "Show Pagination" and $record_per_page > 0 ) {
					echo "<div class='in-sec'><ul class='pagination'>";
						if ( isset($newterm->slug) ) $qrystr = "&tag=".$newterm->slug;													
					echo cs_pagination($count_post, $record_per_page,$qrystr);
					echo "</ul></div>";
				}
				// pagination end
			}
	            ?>
				</div>
                  <?php if($cs_layout != "sixteen columns left"){?>
        <!--Sidebar Start-->
            <div class="one-third column left">
                <?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar($show_sidebar) ) : ?>
                <?php endif; ?>   
            </div>            
        <!--Sidebar Ends-->  
        <?php }?>
           
			</div>
           
<?php get_footer(); ?>